home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 December / december_2000.iso / Intercd / root / Mail / ^MailShield / setup.exe / data1.cab / Default_Rule_Files / standard.mml < prev    next >
Encoding:
Text File  |  2000-10-18  |  4.9 KB  |  131 lines

  1. ##############################################################################
  2. # standard.mml 
  3. #
  4. # Standard MailShield subroutines used in a variety of places.  
  5. #
  6.  
  7. ##############################################################################
  8. # this is the standard (default) rejection notice.
  9.  
  10. sub DefaultRejection {
  11.     # log this rejection as type "log_refuse"
  12.  
  13.     # if log level is 1 or more, then log additional info about this refusal.
  14.     if ($loglevel >= 1) {
  15.         $log_entry = "Unwanted email\n";
  16.         $log_entry .= "  Reason:    ".$log_message."\n";
  17.         $log_entry .= "  State:     ".$state."\n";
  18.         $log_entry .= "  TCP/IP:    ".$PeerHostname." [".$PeerTcpip."]\n";
  19.  
  20.         # log different pieces of information, depending on what mail state was reached
  21.         if ($state_number >= 30) {
  22.             $log_entry .= "  MAIL FROM: ".$SmtpMailFrom."\n";
  23.         };
  24.         if ($state_number >= 40) {
  25.             $log_entry .= "  RCPT TO:   ".join(",", @SmtpRcptTo)."\n";
  26.         };
  27.         if ($state_number >= 50) {
  28.             $log_entry .= "  Subject:   ".&HeaderGet("subject")."\n";
  29.             $log_entry .= "  From:      ".&HeaderGet("from")."\n";
  30.             $log_entry .= "  To:        ".&HeaderGet("to")."\n";
  31.             $log_entry .= "  Date:      ".&HeaderGet("date")."\n";
  32.         };                   
  33.         
  34.         &LogMessage($log_entry, "log_refuse");
  35.     }
  36.     else {
  37.         &LogMessage("Refusing message because '".$log_message."'", "log_refuse");
  38.     };
  39.  
  40.     # Check to see if this message should be sent to a backup server, a backup account, 
  41.     # have the subject marked, or just reject the message.
  42.     # However, if this is a relay rejection, then always reject them, do not defer
  43.     # rejection.
  44.     if ((!$relay_rejection) && ((length($mark_subject) > 0) || (length($backup_mail_server) > 0) || (length($receive_suspicious_email) > 0))) {
  45.         # If the message should not be rejected, but should have some other treatment, first determine
  46.         # if we have received the message yet, or not. If we have not yet received the message, then
  47.         # delay action until the DATA stage.
  48.  
  49.         if ($state eq "DATA") {
  50.             # If we have received the message, then we can treat the message
  51.             &SendMessageToBackup;
  52.         };
  53.  
  54.         # If this message should be rejected, but we have not received the body of message 
  55.         # yet, then delay rejection until we have received the message.
  56.         $send_to_backup = TRUE;
  57.         return;
  58.     };
  59.     
  60.     # If a refusal message was defined, then display it to the SMTP host connected to us
  61.     if ($helpful_refuse_message) {
  62.         &Message($log_message);
  63.     }
  64.     else {
  65.         &Message($smtp_message);
  66.     };
  67.  
  68.     # hang up
  69.     &Hangup;
  70. };
  71.  
  72. sub SendMessageToBackup {
  73.  
  74.     if (length($mark_subject) > 0) {
  75.         # if we have been told to mark the subject rather than rejecting the message, then do that.
  76.  
  77.         # First, get the current header text from $Header
  78.         &HeaderParse($Header);  
  79.         # Then, re-set the Subject
  80.         &HeaderSet("subject", $mark_subject.&HeaderGet("subject"));
  81.         # Finally, commit the changes to the $Header variable
  82.         $Header = &HeaderBuild;
  83.     };
  84.  
  85.     if (length($receive_suspicious_email) > 0) {
  86.         # Redirect rejected mail to a backup email address, if one is defined.
  87.         # Tell the sender that we received the message ok, so that they don't think there's a problem.
  88.         $Header .= "\nX-Originally-To: ".join(", ", @SmtpRcptTo).
  89.                    "\nX-Redirected-To: ".$receive_suspicious_email;
  90.         undef @SmtpRcptTo;
  91.         push(@SmtpRcptTo, $receive_suspicious_email);
  92.     };
  93.     
  94.     if (length($backup_mail_server) > 0) {
  95.         # redirect this email message to a backup mail server, if one is defined
  96.         $smtp_server = $backup_mail_server;
  97.     };
  98.  
  99.     $Header .= "\nX-Reason: ".$log_message;
  100.  
  101.     &CommitHeader;
  102.     &Accept;
  103. };
  104.  
  105.  
  106. ##############################################################################
  107. # redirect this message to the administrator.
  108.  
  109. sub RedirectToAdmin {
  110.  
  111.     # add the original recipient list to the header, then clear the recipient list
  112.     $Header .= "\nX-Originally-To".join(", ", @SmtpRcptTo);
  113.     undef @SmtpRcptTo;
  114.     
  115.     # insert a header to indicate that this message is being forwarded
  116.     $Header .= "\nX-Redirected-To".$receive_suspicious_email;
  117.     &CommitHeaders;
  118.     
  119.     # redefine the recipient list to be the admin email address designated
  120.     # to receive suspicious email.
  121.     push(@SmtpRcptTo, $receive_suspicious_email);
  122.     
  123.     # make a note in the log of this redirecting.
  124.     &LogMessage("Redirecting suspicious email from SMTP host: ".$PeerHostname. " to ".$receive_suspicious_email, "log_refuse");
  125.     
  126.     # accept the message, so as to prevent further processing of it.
  127.     &Accept;
  128. };
  129.  
  130.  
  131.